package store.controller;

import store.dao.CategoryDAO;
import store.po.Category;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/category/edit")
public class EditCategory extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Category c=new Category();
        c.setId(Integer.parseInt(request.getParameter("id")));
        c.setName(request.getParameter("name"));
        c.setDescription(request.getParameter("description"));
        try {
            new CategoryDAO().update(c);
            request.getRequestDispatcher("/category/list").forward(request,response);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }

}
